<template>
	<view class="page">
		<view class="tab">
			<text v-for="v in tabs" :key="v.key" :class="{'tab-active' : v.key === current}" @click="tabChange(v)">
				{{v.name}}
			</text>
		</view>
		<view class="ranking">
			<view class="rangking-title">
				<text>排名</text>
				<text>名称</text>
				<text>业绩</text>
			</view>
			<view class="ranking-list">
				<view class="ranking-list-item" v-for="(item, key) in list" :key="key">
					<view v-if="key < 3" class="ranking-list-number">
						<image :src="'/static/images/ranking/' + (key + 1) + '.png'"></image>
					</view>
					<view v-else class="ranking-list-number">
						<text>{{key + 1}}</text>
					</view>
					<view class="ranking-list-nickname">
						<image v-if="item.image" :src="item.image"></image>
						<image v-else src="/static/images/user/default.png"></image>
						<text>{{item.name}}</text>
					</view>
					<text class="ranking-list-score">{{item.sum}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				tabs: [{
						name: '日榜',
						key: 1
					},
					{
						name: '周榜',
						key: 2
					},
					{
						name: '月榜',
						key: 3
					}
				],
				list: []
			}
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			loadData() {
				this.$func.wmzmall.call('ranking/get', {
					type: this.current
				}).then(res => {
					if (res.code == 200) {
						this.list = res.datas.data
					}
				});
			},
			tabChange(e) {
				this.current = e.key;
				this.loadData()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #3F51B5;
	}

	.page {
		padding-bottom: 20rpx;

		.tab {
			width: 700rpx;
			margin: auto;
			display: flex;
			justify-content: center;
			align-items: flex-end;
			padding: 25rpx;

			text {
				display: block;
				width: 120rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				color: #fff;
				font-size: 14px;
			}

			.tab-active {
				font-size: 16px;
				font-weight: bold;
				position: relative;

				&::after {
					content: '';
					width: 40rpx;
					height: 6rpx;
					border-radius: 4rpx;
					background: #fff;
					position: absolute;
					left: 40rpx;
					bottom: 0;
				}
			}

		}

		.ranking {
			width: 700rpx;
			border-radius: 30rpx;
			margin: auto;
			box-sizing: border-box;
			padding: 20rpx;

			.rangking-title {
				display: flex;
				font-size: 12px;
				color: #f0f0f0;
				height: 50rpx;
				line-height: 50rpx;

				text {
					display: block;
					width: 100rpx;
					text-align: center;

					&:nth-child(2) {
						box-sizing: border-box;
						padding-left: 20rpx;
						text-align: left;
						width: calc(100% - 200rpx);
					}
				}
			}

			.ranking-list-item {
				height: 110rpx;
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				font-size: 14px;
				background: rgba(255, 255, 255, 0.7);
				margin: 16rpx 0;

				&:nth-child(1) {
					background: #efb300;
				}

				&:nth-child(2) {
					background: #b4b0b0;
				}

				&:nth-child(3) {
					background: #e37d19;
				}

				.ranking-list-number {
					width: 100rpx;
					color: #777;
					display: flex;
					justify-content: center;

					image {
						width: 50rpx;
						height: 50rpx;
					}
				}

				.ranking-list-score {
					display: block;
					width: 100rpx;
					color: #555;
					font-size: 16px;
					text-align: center;
				}

				.ranking-list-nickname {
					display: flex;
					align-items: center;
					width: calc(100% - 200rpx);
					box-sizing: border-box;
					padding-left: 20rpx;

					image {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}

					text {
						width: auto;
					}
				}
			}
		}
	}
</style>